package com.shujia.wyh.mr.zuoye;

import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

import java.io.IOException;

/*
    王五,12月2号
    王五,12月2号,30
    王二麻,12月2号,0
    王二麻,12月2号,,
    王二麻,12月2号, ,
 */
public class MyMoneyMapper extends Mapper<LongWritable, Text, Text, LongWritable> {
    @Override
    protected void map(LongWritable key, Text value, Mapper<LongWritable, Text, Text, LongWritable>.Context context) throws IOException, InterruptedException {
        String line = value.toString();
        String[] strings = line.split(",");
        if(strings.length==2){
            context.write(new Text(strings[0]),new LongWritable(10L));
        }else if(strings.length==3){
            if("".equals(strings[2])){
                context.write(new Text(strings[0]),new LongWritable(10L));
            }else if(" ".equals(strings[2])){
                context.write(new Text(strings[0]),new LongWritable(10L));
            }else {
                context.write(new Text(strings[0]),new LongWritable(Long.parseLong(strings[2])));
            }
        }
    }
}
